package coder520.mq.controller.service;

import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * 消息中间件
 */

@Component
public class QueueSend {

        @Autowired
        @Qualifier("queueTemplate")
        private JmsTemplate template;




        public void send(String queueName,final String message){

                //设置持久化
                //template.setDeliveryMode(DeliveryMode.NON_PERSISTENT);//不要持久化
                template.send(queueName, new MessageCreator() {
                        @Override
                        public Message createMessage(Session session) throws JMSException {
                                return session.createTextMessage(message);
                        }
                });

        }



}
